import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { CommonClient } from 'tencentcloud-sdk-nodejs-common';

@Injectable()
export class TencentService {
  private readonly secretId: string;
  private readonly secretKey: string;
  constructor(private readonly config: ConfigService) {
    this.secretId = this.config.get('tencent.secretId');
    this.secretKey = this.config.get('tencent.secretKey');
  }

  async describeCaptchaResult(params: any = {}) {
    const clientConfig = {
      credential: {
        secretId: this.secretId,
        secretKey: this.secretKey,
      },
      region: '',
      profile: {
        httpProfile: {
          endpoint: 'captcha.tencentcloudapi.com',
        },
      },
    };
    const client = new CommonClient(
      'captcha.tencentcloudapi.com',
      '2019-07-22',
      clientConfig,
    );
    return await client.request('DescribeCaptchaResult', {
      ...params,
      CaptchaType: 9,
      CaptchaAppId: Number(this.config.get('tencent.captchaAppId')),
      AppSecretKey: this.config.get('tencent.captchaAppSecret'),
    });
  }
}
